<?php
namespace Enkuso\PropertyBundle\DataFixtures\ORM;

use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
use Nimo\Bundle\BookstoreApiBundle\Entity\Book\Book;

class LoadBookData extends AbstractFixture implements OrderedFixtureInterface
{
    /**
     * {@inheritDoc}
     */
    public function load(ObjectManager $manager)
    {
        $book= new Book();
        $book->setTitle('Twilight');
        $book->setBestseller(true);
        $book->setBrief('When 17 year old Isabella Swan moves to Forks, Washington to live with her father she expects that her new life will be as dull as the town. But in spite of her awkward manner and low expectations, she finds that her new classmates are drawn to this pale, dark-haired new girl in town. But not, it seems, the Cullen family. These five adopted brothers and sisters obviously prefer their own company and will make no exception for Bella. Bella is convinced that Edward Cullen in particular hates her, but she feels a strange attraction to him, although his hostility makes her feel almost physically ill. He seems determined to push her away - until, that is, he saves her life from an out of control car. Bella will soon discover that there is a very good reason for Edward\u2019s coldness. He, and his family, are vampires - and he knows how dangerous it is for others to get too close.');
        $book->setCategory($this->getReference('book-category-literature'));
        $book->setCover('http://upload.wikimedia.org/wikipedia/en/thumb/b/b6/Twilight_(2008_film)_poster.jpg/220px-Twilight_(2008_film)_poster.jpg');
        $book->setIsbnCode('');
        $book->setIsDraft(false);
        $book->setLanguage('English');
        $book->setMeta('');
        $book->setLastViewedDate(new \DateTime('now'));
        $book->setPageCount(464);
        $book->setPress('StephenieMeyer.com');
        $book->setPublishedYear('2005');
        $book->setRating(5);
        $book->setPrice(19.99);
        $book->addTag($this->getReference('book-tag-vampire'));
        $book->addTag($this->getReference('book-tag-saga'));

        $manager->persist($book);
        $manager->flush();

        $this->addReference('book', $book);
    }

    /**
     * {@inheritDoc}
     */
    public function getOrder()
    {
        return 99; // the order in which fixtures will be loaded
    }
}
